<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户编辑</title>
    <link rel="stylesheet" href="public/layui/css/layui.css">
    <script src="./public/layui/layui.js"></script>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>

<body>
    <form class="layui-form layui-form-pane layui-padding-3" lay-filter="edit" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="username" autocomplete="off" placeholder="请输入" lay-verify="required"
                    class="layui-input" disabled>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" name="password" placeholder="不修改则留空"  autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="email" name="email" placeholder="email"  autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select name="status">
                    <option value="">请选择用户状态</option>
                    <option value="0">待审核</option>
                    <option value="1" >正常</option>
                    <option value="2">封禁</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">积分</label>
            <div class="layui-input-inline">
                <input type="number" lay-verify="required" lay-affix="number" name="score" placeholder="积分" step="10"
                min="0" class="layui-input" value="0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户会员</label>
            <div class="layui-input-inline">
                <input type="text" name="vip_time" autocomplete="off" placeholder="非会员" 
                    class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员数量</label>
            <div class="layui-input-inline">
                <input type="number" lay-verify="required" lay-affix="number" name="vip_count" placeholder="积分" step="10"
                    min="0" class="layui-input" value="0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员类型</label>
            <div class="layui-input-inline">
                <select name="vip_type">
                    <option value="0">时</option>
                    <option value="1">天</option>
                    <option value="2">月</option>
                    <option value="3">年</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员操作</label>
            <div class="layui-input-block">
              <input type="radio" name="type_s" value="1" title="增加" checked>
              <input type="radio" name="type_s" value="2" title="减少">
            </div>
          </div>
        <input type="text" hidden name="id" value="<{$data.id}>" id="">
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit lay-filter="edit">修改</button>
        </div>
    </form>
    <script>
        layui.use(function () {
            var form = layui.form
            var $ = layui.$
            form.val('edit', {
                username: "<{$data.username}>"
                , score: "<{$data.score}>"
                , status: "<{$data.status}>"
                , email: "<{$data.email}>"
                , vip_time:"<{$data.vip_time}>"
            })
            form.on('submit(edit)', function (data) {
                field = data.field
                hour = 3600
                if (field.vip_type == 0) {
                    i = hour
                } else if (field.vip_type == 1) {
                    i = hour * 24
                } else if (field.vip_type == 2) {
                    i = hour * 24 * 30
                } else if (field.vip_type == 3) {
                    i = hour * 24 * 365
                }
                vip_time = i * field.vip_count
                field.vip_time = vip_time
                delete field.vip_type, delete field.vip_count
                $.post('?p=admin&c=user&a=doEdit', field, (res) => {
                    if (res.code == 200) {
                        layer.msg('修改成功')
                    } else {
                        layer.msg(res.msg)
                    }
                })
                return false
            })
        })
    </script>
</body>

</html>